<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
 <%
  String xm = this.getServletContext().getInitParameter("path");
	String path1 = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+"/"+xm;
%>  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>添加订单信息</title>
<link href="<%=path1%>/css/css.css" rel="stylesheet" type="text/css" />


<script type="text/javascript" src="<%=path1%>/scripts/jquery-1.7.2.js"></script>
<script type="text/javascript" src="<%=path1%>/scripts/pagekage/utils/widget/jqGrid/jquery.jqGrid.src.js"></script>
<script type="text/javascript" src="<%=path1%>/scripts/pagekage/utils/widget/jqGrid/i18n/grid.locale-cn.js"></script>
<script type="text/javascript" src="<%=path1%>/scripts/pagekage/utils/widget/jqGrid/jquery.jqGrid.min.js"></script>
 <script type="text/javascript" src="<%=path1%>/qt/js/autoOrder.js" charset="UTF-8"></script>
  <script type="text/javascript" src="<%=path1%>/qt/js/autoCustomer.js" charset="UTF-8"></script>
<!--[if IE 6]>
<script type="text/javascript" src="js/ie6png.js" ></script>
<script type="text/javascript">
DD_belatedPNG.fix('div,ul,li,a,p,img,body,dl,dt,dd');</script>
<![endif]-->
<script type="text/javascript">
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
</script>
<script>
<!--
/*第一种形式 第二种形式 更换显示样式*/
function setTab(name,cursel,n){
for(i=1;i<=n;i++){
var menu=document.getElementById(name+i);
var con=document.getElementById("con_"+name+"_"+i);
menu.className=i==cursel?"hover":"";
con.style.display=i==cursel?"block":"none";
}
}
//-->
</script>
<script type="text/javascript">
//添加
    function ajaxPost(){
   
        $.ajax({ 	
        data:{customer_name:$("#customer_name").val(),
        	tel:$("#tel").val(),
        	sex:$("input[name='sex']:checked").val(),
        	customer_type:$("input[name='customer_type']:checked").val(),
        	describel:$("#describel").val(),
        	maritalStatus:$("#maritalStatus").val(),
        	address:$("#address").val(),
        	id_number:$("#id_number").val(),
        	
        	profession:$("#profession").val(),
        	income_level:$("#income_level").val(),
        	
        },
        type:"Post",  
        dataType: 'json',  
        url:"./Customer/addCustomer.do", 
        error:function(data){ 
        	alert(data);
             alert("出错了！！");  
        },  
        success:function(data){
        	
        	alert(data);
        	alert('客户信息添加成功！');
        	window.location.href = 'listCustomer.jsp'; 
         }  
         });  
     } 
    // 重置
    function ajaxReset(){
    	$("#customerName").val("");
    	$("#tel").val("");
    	$("input:radio[name='sex']").eq(0).attr("checked",true);
    	$("input:radio[name='customerType']").eq(0).attr("checked",true);
    	$("#paperstType").val("");
		$("#paperstNo").val("");
		$("#eduStatus").val("");
		$("#profession").val("");
		$("#income").val("");
		$("#maritalStatus").val("");
		$("#address").val("");
    }
    
    function selectbuile(){
    	var buildValue = $("#build_name").val();
    	var searchSqlbuider ='';
    	var selectsUnitCode =null;
    	if(!(buildValue==null || buildValue =="")){
    		searchSqlbuider = "and build_id='"+buildValue+"'GROUP by unit_code";
    	}
    	$("#unit_code").empty();
    	  selectsUnitCode = document.getElementById("unit_code");
    	   $.post("./Order/unit/SelectBySql.do",
    	    		  {"seacherSql":searchSqlbuider},
    	    		  function (data) {
    	    			  var text = "请选择单元";
    	    			  var opCustomerName=document.createElement("option");      
    	    	         opCustomerName.setAttribute("value",'');   
    	    			  if(data.rows.length==0){
    	    				text = "没有相应的数据";
    	    			  }
    	    			  opCustomerName.appendChild(document.createTextNode(text)); 
    	    			  selectsUnitCode.appendChild(opCustomerName);
    	    			  for(var a =0; a<data.rows.length;a++){
    	      				var opCustomerName=document.createElement("option");      
    	  		         	opCustomerName.setAttribute("value",data.rows[a].unit_id);        
    	  		         	opCustomerName.appendChild(document.createTextNode(data.rows[a].unit_code)); 
    	  		         	selectsUnitCode.appendChild(opCustomerName);   
    	    			  }
    	    		  });
    	
    }

	function selectunit() {
		//选择房间
		var unitValue = $("#unit_code").val();
		console.log("单元编号" + unitValue);
		var SearchSqlbuider = '';
		var selectsUnitCode = null;
		if (!(unitValue == null || unitValue == "")) {
			SearchSqlbuider = "and unit_id='" + unitValue + "'";
		}
		$("#room_code").empty();
		selectsUnitCode = document.getElementById("room_code");
		$.post("./Order/room/selectBySql.do",
			{"seacherSql" : SearchSqlbuider},
			function(data) {
			var text = "请选择房间";
			var opCustomerName = document.createElement("option");
			opCustomerName.setAttribute("value", '');
			if (data.rows.length == 0) {
				text = "没有相应的数据";
			}
			opCustomerName.appendChild(document.createTextNode(text));
			selectsUnitCode.appendChild(opCustomerName);
			for (var a = 0; a < data.rows.length; a++) {
				var opCustomerName = document.createElement("option");
				opCustomerName.setAttribute("value", data.rows[a].room_id);
				opCustomerName.appendChild(document
						.createTextNode(data.rows[a].room_code));
				selectsUnitCode.appendChild(opCustomerName);
			}
		});
	}
	function selectRoom(){
		//选择房间
		var unitValue = $("#room_code").val();
		console.log("房间编号" + unitValue);
		var SearchSqlbuider = '';
		var selectsUnitCode = null;
		if (!(unitValue == null || unitValue == "")) {
			SearchSqlbuider = "and room_id='" + unitValue + "'";
		}
		$.post("./Order/room/selectBySql.do",
			{"seacherSql" : SearchSqlbuider},
			function(data) {
				
			$("#unit_price").val(data.rows[0].inner_price);
			$("#pay_area").val(data.rows[0].build_up_area);
			$("#total").val((data.rows[0].inner_price)*(data.rows[0].build_up_area));
			});
	}
</script>
<script type="text/javascript">
   function checkcustomerName(){
	  var customerName= $("#customerName").val();
	  if(customerName==""){
		 alert("客户名称不能为空！"); 
		 $("#customerName").focus();
		 return false;
	  }
	  return true;
   }
   function checktel(){
	   var tel=$("#tel").val();
		  if(tel==""){
			 alert("联系电话不能为空！"); 
			 $("#tel").focus();
			 return false;
		  }
		  return true;
   }
   function tel(){
	   var tel=$("#tel").val();
	   var phone=/^1\d{10}$/;
	   var mobile=/^0\d{2,3}-?\d{7,8}$/;
	   if (phone.test(tel) || mobile.test(tel)) { 
		      //alert("号码正确~"); 
		 }else{ 
		      alert("号码有误~"); 
		      $("#tel").focus();
		 };
   }
   function paperstNo(){
	   var no=$("#paperstNo").val();
	   var paperstNo=/^\d{17}([0-9]|X)$/;
	   if (paperstNo.test(no)) { 
		      //alert("身份证号码正确~"); 
		 }else{ 
		      alert("身份证号码有误~"); 
		      $("#paperstNo").focus();
		 };
   }
   function orderSubmit(){
	   var bool = true;
    var arr = new Array();
	arr[0]= $("#project_name").val();
	arr[1]= $("#unit_code").val();
	arr[2]= $("#room_code").val();
	arr[3]= $("#unit_price").val();
	arr[4]= $("#total").val();
	arr[5]= $("#pay_area").val();
	arr[6]= $("#customer_name").val();
	arr[7]= $("#deposit").val();
	arr[8]= $("#pay_type_id").val();
	arr[9]= $("#order_type").val();
	arr[10]= $("#customer_name").attr("name");
	console.log(arr[10]);
	 for(var i=0;i<arr.length;i++){
		  if(arr[i]==null || arr[i] ==''){
			  alert("请完成操作再提交！");
			  break;
			  return;
		  }
		 }
	 $.post("./Order/addOrder.do",
	  		  {
		     "project_name": arr[0],
		     "unit_code": arr[1],
		     "room_id": arr[2],
		     "unit_price": arr[3],
		     "total": arr[4],
		     "pay_area": arr[5],
		     "customer_name": arr[6],
		     "deposit": arr[7],
		     "pay_type_id": arr[8],
		     "orderType": arr[9],
		     "customer_id":arr[10]
	  		  },
	  		  function (data) {
	  			 console.log(data);
	  			window.location.href = "listOrder.jsp";
	  		  });
	    
   }
  
   </script>
</head>
<body>
<div class="yboxwidth boxcenter">
  <div class="ybox09">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
       <td style="padding-left: 20px"><table border="0" cellspacing="0" cellpadding="0">
          <tr valign="top" >
            <td class="ybox11td5" ></td>
            <td class="ybox11td6" >填写订单信息</td>
            <td class="ybox11td7"></td>
            <td class="ybox11td2"></td>
            <td class="ybox11td3"></td>
            <td class="ybox11td2"></td>
            <td class="ybox11td3"></td>
            <td class="ybox11td2"></td>
            <td class="ybox11td4"></td>    
          </tr>
        </table></td>
        </tr>
    </table>
  </div>
  <div class="ybox02">
    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="margb4">
      <tr>
        <td class="ybox03td1"></td>
        <td class="ybox03td2"></td>
        <td class="ybox03td3"></td>
      </tr>
      <tr>
        <td class="ybox03td4"></td>
        <td class="ybox03td5"><div class="ybox05 margb8">
            <dl>
              <dt><strong>房间基本信息</strong> </dt>
            </dl>
          </div>
          <table width="100%" border="0" cellpadding="0" cellspacing="1" class="ybox04table">
            <tr>
              <td width="10%" class="ybox04tdl"><span class="red">*</span>选择项目</td>
              <td width="13%" class="ybox04tdr">
              <input id="project_name" name="project_name" type="text"  class="black12" style="width:90%;" />
              	<div id="sdiv"></div>
              </td>
              <td width="10%" class="ybox04tdl"><span class="red">*</span>选择楼栋</td>
              <td width="13%" class="ybox04tdr">
                 <select name="build_name"   class="black12" id="build_name" style="width:90%;" onchange="selectbuile()">
                    
                  </select>
              </td>
               <td width="10%" class="ybox04tdl"><span class="red">*</span>选择单元</td>
              <td width="13%" class="ybox04tdr">
                  <select name="unit_code"   class="black12" id="unit_code" style="width:90%;"  onchange="selectunit()">
                    
                  </select>
              </td>
               <td width="10%" class="ybox04tdl"><span class="red">*</span>选择房间</td>
              <td width="13%" class="ybox04tdr"><select name="room_code" onchange="selectRoom()"  class="black12" id="room_code" style="width:90%;" ></select></td>
            </tr>
            <!-- 1111111111111111111111111111111111 -->
              <tr>
              <td width="10%" class="ybox04tdl"><span class="red">*</span>每平米房间单价</td>
              <td width="13%" class="ybox04tdr">
              <input readonly="readonly" id="unit_price" name="unit_price" type="text"  class="black12" style="width:90%;" />
              </td>
               <td width="10%" class="ybox04tdl"><span class="red">*</span>房间总价</td>
              <td width="13%" class="ybox04tdr">
                  <input  name="total" type="text" readonly="readonly"  class="black12" id="total" style="width:90%;"/>
              </td>
               <td width="10%" class="ybox04tdl"><span class="red">*</span>购买面积</td>
              <td width="13%" class="ybox04tdr">
                   <input readonly="readonly" name="pay_area"   class="black12" id="pay_area" style="width:90%;" />
              </td>
            </tr>
          </table></td>
        <td class="ybox03td6"></td>
      </tr>
     <tr height="20" ><td colspan="6" bgcolor="#e9f7ff"></td></tr>
      <tr>
        <td class="ybox03td4"></td>
        <td class="ybox03td5"><div class="ybox05 margb8">
            <dl>
              <dt><strong>详细信息</strong> </dt>
            </dl>
          </div>
          <table width="100%" border="0" cellpadding="0" cellspacing="1" class="ybox04table">
            <tr>
            <td width="15%" class="ybox04tdl">客户名称</td>
            <td width="18%" class="ybox04tdr">
                <input type="text" name="customer_name" style="width:90%;" id="customer_name" />
                <div id="customer_div"></div>
            </td>
            

              <td width="15%" class="ybox04tdl">保证金</td>
               <td width="18%" class="ybox04tdr"> 
               <input type="text" name="deposit" class="black12" id="deposit" style="width:90%;" />
              </td> 
            
            </tr>
             
            <tr>
              <td width="15%" class="ybox04tdl">付款方式</td>
              <td width="18%" class="ybox04tdr">
              <select name="pay_type_id" class="black12" id="pay_type_id"  style="width:90%;" />
              
              </td>
              
              	   <td width="15%" class="ybox04tdl">订单类型</td>
              <td width="18%" class="ybox04tdr">
              <select name="order_type"   class="black12" id="order_type" style="width:90%;" >
              <option>标准采购订单</option>
              <option>合同采购订单</option>
              <option>计划采购订单</option>
              </select>
              </td>   
            </tr>
            <tr>
            <td width="18%" colspan="6" class="ybox04tdr">
              
               <dl>
                 <dt><strong>【注】</strong> 
                 1.基本信息为必填项</br>
                 2.详细信息必须在用户下订单之前填写完整
              </dt>
               </dl>
            </td>
            </tr>
            
          </table></td>
        <td class="ybox03td6"></td>
      </tr>
      <tr>
        <td class="ybox03td7"></td>
        <td class="ybox03td8"></td>
        <td class="ybox03td9"></td>
      </tr>
    </table>
    <table width="380" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td height="60" align="center"> <img src="images/bottoncommit.gif"  style="cursor: pointer;"width="95" height="34" onclick="return orderSubmit()" /></td>
        <td height="60" align="center"><img src="images/bottonreset.gif" style="cursor: pointer;" width="95" height="34" onclick="ajaxReset()" /></td>
      </tr>
    </table>
  </div>
</div>
</body>
</html>
